package com.xiaochun.hxhj;


import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tencent.mm.sdk.modelmsg.SendAuth;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.util.InfoEventMessage;
import com.util.MyLog;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
//启动页一张图片3到5秒------视频页面（第一次）---首页---------（修改密码）

public class LoginActivity extends BaseActivity implements View.OnClickListener {

    private TextView tv_login_register;
    private TextView tv_wxlogin;
    private LinearLayout ll_xieyi;
    private IWXAPI api;
    private LinearLayout ll_register;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        myapp.addDestoryActivity(this,getClass().getName());
        MyLog.e("登陆页面",getClass().getName());
//        EventBus.getDefault().register(this);
        initView();
    }

    @Override
    protected void initListener() {
        tv_login_register.setOnClickListener(this);
        tv_wxlogin.setOnClickListener(this);
        ll_register.setOnClickListener(this);
        ll_xieyi.setOnClickListener(this);

    }
    @Subscribe
    public void onEventMainThread(InfoEventMessage event) {
        String message = event.getMessage();
        Log.e("GTPCmessage--new--order", message);
        if ("登录页面finish".equals(message)){
            finish();
        }


    }

    @Override
    protected int initLayout() {
        return R.layout.activity_login;
    }
    @Override
    protected void initView() {
        changeTitle("用户登录");
        showRightView(false);
        hideTitleBar();
        tv_login_register = findViewById(R.id.tv_login_register);
        tv_wxlogin = findViewById(R.id.tv_wxlogin);
        ll_xieyi = findViewById(R.id.ll_xieyi);
        ll_register = findViewById(R.id.ll_register);

    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View view) {
        Intent intent = null;
        switch (view.getId()){
            case R.id.tv_login_register:
                intent = new Intent(context,LoginByMobileActivity.class);
                startActivity(intent);
                break;
            case R.id.tv_wxlogin:
                String appid = myapp.getAppId();
                SendAuth.Req req = new SendAuth.Req();
                req.scope = "snsapi_userinfo";
                req.state = "none";
                api = WXAPIFactory.createWXAPI(LoginActivity.this, appid, true);
                api.registerApp(appid);
                api.sendReq(req);
                break;
            case R.id.ll_xieyi:
                intent = new Intent(context,WebviewActivity.class);
                intent.putExtra("url", myapp.getSiteurlweb() + "/#/yinsi");
                startActivity(intent);
                break;
            case R.id.ll_register:
                intent = new Intent(context,RegisterActivity.class);
                startActivity(intent);
                break;
        }
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (keyCode == KeyEvent.KEYCODE_BACK) {
            String isRestarApp = getUserInfo("isRestarApp");
            if ("true".equals(isRestarApp)){
                Intent intent = new Intent(context,MainActivity.class);
                startActivity(intent);
            }
            finish();


        }
        return false;
    }

}
